import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By  # todo:引入By方法，做selenium定位
from time import sleep
from selenium.webdriver.chrome.service import Service
import allure

# allure报告级别：feature、story、step

# pytest [测试文件] --alluredir=allure
# allure generate ./allure/ -o ./reports --clean

@allure.feature("浙江省医院搜索测试用例")
class TestGK:
    @pytest.fixture(scope='function',autouse=True)
    def setup_teardown(self):
        option = webdriver.ChromeOptions()
        option.add_experimental_option("detach", True)
        self.bro = webdriver.Chrome(options=option,service=Service('./chromedriver.exe'))
        self.bro.implicitly_wait(15)
        self.bro.get("http://www.bjhospital.net/")
        self.bro.maximize_window()
        yield
        self.bro.quit()
    @allure.story("搜索骨科")
    def test_search(self):
        # 搜索骨科
        with allure.step("搜索骨科"):
            self.bro.find_element(By.XPATH, '//*[@id="header"]/div/div/div/form/input[2]').send_keys('骨科')
        # 点击搜索
        with allure.step("点击搜索"):
            self.bro.find_element(By.XPATH, '//*[@id="header"]/div/div/div/form/button').click()
        # 点击出来的第一个链接
        with allure.step("点击出来的第一个链接"):
            self.bro.find_element(By.XPATH, '/html/body/div[4]/ul/li[1]/div[1]/h5/a').click()
        # 断言文本内
        with allure.step("断言文本内"):
            jubing = self.bro.window_handles
            self.bro.switch_to.window(jubing[-1])
            txt1 = self.bro.find_element(By.XPATH, '/html/body/div[3]/div/div/article/h1').text
            assert txt1 == '毕节市第一人民医院高值医用耗材网上阳光平台议价意向公开'
        sleep(5)


